package ca.etsmtl.log430.lab3.gestion;


/**
 * This class defines the Course object for the system.
 * 
 * @author A.J. Lattanze, CMU
 * @version 1.4, 2012-Feb-02
 */
import ca.etsmtl.log430.lab3.gestion.ifaces.*;
import ca.etsmtl.log430.lab3.gestion.list.TeacherList;

/*
 * Modification Log **********************************************************
 * V 2.0 A
 * 
 * 
 * */
public class Course implements ICourse {

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((courseID == null) ? 0 : courseID.hashCode());
		result = prime * result
				+ ((courseName == null) ? 0 : courseName.hashCode());
		result = prime * result
				+ ((courseTimeSlot == null) ? 0 : courseTimeSlot.hashCode());
		result = prime * result + ((group == null) ? 0 : group.hashCode());
		result = prime * result
				+ ((labTimeSlot == null) ? 0 : labTimeSlot.hashCode());
		result = prime
				* result
				+ ((teachersAssigned == null) ? 0 : teachersAssigned.hashCode());
		result = prime * result + ((type == null) ? 0 : type.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Course other = (Course) obj;
		if (courseID == null) {
			if (other.courseID != null)
				return false;
		} else if (!courseID.equals(other.courseID))
			return false;
		if (courseName == null) {
			if (other.courseName != null)
				return false;
		} else if (!courseName.equals(other.courseName))
			return false;
		if (courseTimeSlot == null) {
			if (other.courseTimeSlot != null)
				return false;
		} else if (!courseTimeSlot.equals(other.courseTimeSlot))
			return false;
		if (group == null) {
			if (other.group != null)
				return false;
		} else if (!group.equals(other.group))
			return false;
		if (labTimeSlot == null) {
			if (other.labTimeSlot != null)
				return false;
		} else if (!labTimeSlot.equals(other.labTimeSlot))
			return false;
		if (teachersAssigned == null) {
			if (other.teachersAssigned != null)
				return false;
		} else if (!teachersAssigned.equals(other.teachersAssigned))
			return false;
		if (type != other.type)
			return false;
		return true;
	}

	/**
	 * Course title
	 * @uml.property  name="courseName"
	 */
	private String courseName;

	/**
	 * Course ID
	 * @uml.property  name="courseID"
	 */
	private String courseID;

	/**
	 * Course type (course = CRS, laboratory = LAB)
	 * @uml.property  name="type"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private CourseType type;

	/**
	 * Course group
	 * @uml.property  name="group"
	 */
	private String group;

	/**
	 * @uml.property  name="courseTimeSlot"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private TimeSlot courseTimeSlot;
	/**
	 * @uml.property  name="labTimeSlot"
	 * @uml.associationEnd  
	 */
	private TimeSlot labTimeSlot;

	/**
	 * List of teachers assigned to the course
	 * @uml.property  name="teachersAssigned"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private TeacherList teachersAssigned = new TeacherList();

	private Course() {
		this(null);
	} // Constructor

	/**
	 * 
	 * @param CourseID
	 */
	private Course(String CourseID) {
		this.setCourseID(CourseID);
		this.setCourseName(null);
		this.setType(null);
		this.setGroup(null);
		this.setDay(null);
		this.setStartTime(null);
		this.setStopTime(null);
	} // Constructor


	/**
	 * 
	 * @param courseName
	 * @param courseID
	 * @param type
	 * @param group
	 * @param day
	 * @param startTime
	 * @param stopTime
	 */
	public Course(
			String courseName, 
			String courseID, 
			CourseType type,
			String group, 
			String day, 
			String startTime, 
			String stopTime) {
		super();
		this.courseName = courseName;
		this.courseID = courseID;
		this.type = type;
		this.group = group;
		courseTimeSlot = new TimeSlot(day, startTime, stopTime);

		this.teachersAssigned = new TeacherList();
	}
	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#assignTeacher(ca.etsmtl.log430.lab2.gestion.Teacher)
	 */
	@Override
	public boolean assignTeacher(ITeacher teacher) 
	{
		
		teachersAssigned.addTeacher((Teacher) teacher);
		
		return true;
	}

	/**
	 * @param courseName
	 * @uml.property  name="courseName"
	 */
	public void setCourseName(String courseName) {
		this.courseName = courseName;
	}

	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#getCourseName()
	 */
	/**
	 * @return
	 * @uml.property  name="courseName"
	 */
	@Override
	public String getCourseName() {
		return courseName;
	}

	/**
	 * @param courseID
	 * @uml.property  name="courseID"
	 */
	public void setCourseID(String courseID) {
		this.courseID = courseID;
	}

	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#getCourseID()
	 */
	/**
	 * @return
	 * @uml.property  name="courseID"
	 */
	@Override
	public String getCourseID() {
		return courseID;
	}

	/**
	 * @param group
	 * @uml.property  name="group"
	 */
	public void setGroup(String group) {
		this.group = group;
	}

	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#getGroup()
	 */
	/**
	 * @return
	 * @uml.property  name="group"
	 */
	@Override
	public String getGroup() {
		return group;
	}

	public void setDay(String day) {
		 this.courseTimeSlot.setDay(day);		
	}

	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#getDay()
	 */
	@Override
	public String getDay() {
		return this.courseTimeSlot.getDay();	
	}

	public void setStartTime(String startTime) {
		this.courseTimeSlot.setStartTime(startTime);
	}

	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#getStartTime()
	 */
	@Override
	public String getStartTime() {
		
		return courseTimeSlot.getStartTime();
	}

	public void setStopTime(String stopTime) {
		this.courseTimeSlot.setStopTime(stopTime);
	}

	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#getStopTime()
	 */
	@Override
	public String getStopTime() {
		return courseTimeSlot.getStopTime();
	}

	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#getTeachers()
	 */
	@Override
	public TeacherList getTeachers() {
		return teachersAssigned;
	}

	public void setTeachers(TeacherList teachers) {
		teachersAssigned = teachers;
	}

	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#getType()
	 */
	/**
	 * @return
	 * @uml.property  name="type"
	 */
	@Override
	public CourseType getType() {
		return type;
	}


	/**
	 * @param type
	 * @uml.property  name="type"
	 */
	public void setType(CourseType type) {
		this.type = type;
	}

	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#isConflicting(ca.etsmtl.log430.lab2.gestion.CourseManagementInterface)
	 */
	@Override
	public boolean isConflicting(ICourse course) {
		
		return this.courseTimeSlot.equals(course.getCourseTimeSlot());
	}

	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#getCourseTimeSlot()
	 */
	/**
	 * @return
	 * @uml.property  name="courseTimeSlot"
	 */
	@Override
	public TimeSlot getCourseTimeSlot() {
		return courseTimeSlot;
	}

	/**
	 * @param courseTimeSlot
	 * @uml.property  name="courseTimeSlot"
	 */
	public void setCourseTimeSlot(TimeSlot courseTimeSlot) {
		this.courseTimeSlot = courseTimeSlot;
	}

	/* (non-Javadoc)
	 * @see ca.etsmtl.log430.lab2.gestion.CourseManagementInterface#getLabTimeSlot()
	 */
	/**
	 * @return
	 * @uml.property  name="labTimeSlot"
	 */
	@Override
	public TimeSlot getLabTimeSlot() {
		return labTimeSlot;
	}

	/**
	 * @param labTimeSlot
	 * @uml.property  name="labTimeSlot"
	 */
	public void setLabTimeSlot(TimeSlot labTimeSlot) {
		this.labTimeSlot = labTimeSlot;
	}

	
	public String toString()
	{
		return this.courseID+" "+this.courseName+" "+this.group+ " " +this.type;
	}
} // Course class